package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IBorrowPlaceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.BorrowPlaceReqVO;
import com.bjc.base.bean.response.BorrowPlaceVO;

/**
 * <p>
 * 绘本借阅点 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "borrowPlace-api", tags = { "绘本借阅点相关接口" })
public class BorrowPlaceController {

    @Autowired
    private IBorrowPlaceService borrowPlaceService;

	@ApiOperation("分页查询绘本借阅点")
	@GetMapping("borrowPlace/findPage")
	public ResultVO getBorrowPlacePage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			BorrowPlaceReqVO borrowPlaceReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<BorrowPlaceVO> borrowPlaceVOs = borrowPlaceService.getList(borrowPlaceReqVO);
		return ResultGenerator.getSuccess(new PageInfo<BorrowPlaceVO>(borrowPlaceVOs));
	}
	
	@ApiOperation("分页查询绘本借阅点")
	@GetMapping("borrowPlace/find")
	public ResultVO getBorrowPlacee(BorrowPlaceReqVO borrowPlaceReqVO) {
		BorrowPlaceVO borrowPlaceVO = borrowPlaceService.get(borrowPlaceReqVO);
		return ResultGenerator.getSuccess(borrowPlaceVO);
	}

	@ApiOperation("添加绘本借阅点")
	@PostMapping("borrowPlace/create")
	public ResultVO createBorrowPlace(@RequestBody BorrowPlaceReqVO borrowPlaceReqVOs) {
		int count = borrowPlaceService.insert(borrowPlaceReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本借阅点")
	@PutMapping("borrowPlace/update")
	public ResultVO updateBorrowPlace(@RequestBody BorrowPlaceReqVO borrowPlaceReqVOs) {
		int count = borrowPlaceService.update(borrowPlaceReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本借阅点")
	@DeleteMapping("borrowPlace/deleteList")
	public ResultVO deleteBorrowPlace(@ApiParam(value = "borrowPlace id集合") @RequestBody int[] ids) {
		int count = borrowPlaceService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
